;(function(){
  'use strict';
  /**
   * customer 吴尧
   * @ngdoc function
   * @provinceName sasdApp.controller:customerAnalysisController
   * @description 物联网业务量统计分析
   * # customerAnalysisController
   * Controller of the sasApp
   */
  angular.module('controllers.pbossSysBusiness.pbossSysBusinessStastic')
    .controller('businessSuccessRateCtrl', businessSuccessRateCtrl);

  function businessSuccessRateCtrl($scope ,CoreService,sysBusinessStatisticFactory,businessSuccessRateService,$filter,$timeout,COREDATA,CoreLoading,BankAtaServer) {
    $scope.errorInfo = COREDATA.ERRORINFO;   //日期错误信息
    $scope.provinces = COREDATA.PROVINCES;
    $scope.initQuery = function(){
      sysBusinessStatisticFactory.queryBusinessName(function(res){
        $scope.shoumun = 1;
        $scope.businessList = res.data;
        $scope.queryData();
      });
    };
    $scope.translate ={
      searchTime: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1),
      businessCode:'BIP2B958',
    };

    var res = {};
    var searchTime;
    var xData;
    var yData;
    var pbossEcharts = echarts.init(document.getElementById('suceessRate'));
    $scope.queryData = function(){

      $scope.shoumun==1?$scope.shoumun=0:$scope.shoumun=1;

      if($scope.shoumun === 0){
        CoreLoading.setState(true);
        $scope.flagObj = true;
        searchTime = $filter('date')($scope.translate.searchTime,'yyyyMMdd');
        xData = [];
        yData = [];

      businessSuccessRateService.queryBusinessSuccessRate($scope.translate,function(res){
        if(res.state === '10000' && res.data.length >= 1){
        angular.forEach(res.data, function(item){
          xData.push(item.provinceName);
          yData.push(item.successRate);
        });


      var itemStyle =  {
        normal: { // 系列级个性化，横向渐变填充
          borderRadius: 5
        }
      };
       var option = {
         title: {
           text: '开卡业务成交率_'+searchTime,
           x: 'center'
         },
         tooltip: {
           trigger: 'axis',
           axisPointer: {
             type: 'shadow'
           }
         },
         legend: {
           orient: 'vertical',
           x: 'right',
           y: 'center',
           data: ['物联网']
         },
         grid: {
           x2: '8%'
         },
         xAxis: [
           {
             type: 'category',
             data: xData,
             axisLabel : {show:true,interval: 'auto',rotate: 45 }
           }
         ],
         yAxis: [
           {
             type: 'value' ,
             name: '(百分比)',
             min: 80,
             max: 100,
             boundaryGap: [0, 0.1],
             axisLabel : {show:true,formatter: '{value}%' },

           }
         ],
         series: [
           {
             name: '物联网',
             type: 'bar',
             itemStyle: itemStyle,
             data: yData
           }
         ]
       };

       $timeout(function(){
        $scope.flagObj = true;
         CoreLoading.setState(false);
         pbossEcharts.clear();
         pbossEcharts.setOption(option);
       },1000);

       }else if(res.data.length === 0){
            CoreService.dialog('查询无数据');
        }else {
            CoreService.dialog('查询错误');
        }
        CoreLoading.setState(false);
        });
      }
    };
    $scope.queryData();
  }
})();

